package com.zsrt.java.day20161223.hzj;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

	@Test
	public void hw1(){
		
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个有效的年份");
		int year = sc.nextInt();
		sc.close();
		
		if(0==year%400){
			System.out.println(year+"是闰年");
		}else if(0==year%4 && 0!=year%100){
			System.out.println(year+"是闰年");
		}else{
			System.out.println(year+"不是闰年");
		}
	}
	
	@Test
	public void hw02(){
		
		int a=10;
		int b=5;
		int c;
		System.out.println("开始:a的值："+a+"  b的值"+b);
		if(a>b){
			
			c=a;
			a=b;
			b=c;
		}
		System.out.println("结尾:a的值："+a+"  b的值"+b);
	}
	
	@Test
	public void hw3(){
		
		int a=10;
		int b=5;
		int max;
		if(a>b)
			max = a;
		else
			max = b;
		System.out.println("最大值是"+max);
	}
	
	@Test
	public void hw04(){
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个有效的成绩");
		int source = sc.nextInt();
		sc.close();
		if(source>=90){
			System.out.println("优秀");
		}else if(source>=80){
			System.out.println("良好");
		}else if(source>=60){
			System.out.println("及格");
		}else{
			System.out.println("不及格");
		}
	}
	
	@Test
	public void hw05(){
		
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个有效的成绩");
		String source = sc.next();
		sc.close();
		
		switch(source){
		
		case "A": System.out.println("优秀");break;
		case "B": System.out.println("良好");break;
		case "C": System.out.println("及格");break;
		default: System.out.println("不及格");break;
		}
		
	}
	
	
    @Test
    public void hw7(){
    	
    	Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个数值");
		int a = sc.nextInt();
		System.out.println("请输入一个符号");
		String s = sc.next();
		int b;
		
		switch(s){
		
		case "+": 
			System.out.println("请输入一个数值");
			 b = sc.nextInt();
            System.out.println(a+s+b+"="+(a+b));
            sc.close();
			break;
		case "-":
			System.out.println("请输入一个数值");
			 b = sc.nextInt();
            System.out.println(a+s+b+"="+(a-b));
            sc.close();
			break;
		case "*":
			System.out.println("请输入一个数值");
			 b = sc.nextInt();
            System.out.println(a+s+b+"="+(a*b));
            sc.close();
			break;
		case "/": 
			System.out.println("请输入一个数值");
			 b = sc.nextInt();
            System.out.println(a+s+b+"="+(a/b));
            sc.close();
			break;
		case "%":
			System.out.println("请输入一个数值");
			 b = sc.nextInt();
            System.out.println(a+s+b+"="+(a%b));
            sc.close();
			break;
		default: System.out.println("符号不正确");break;
		}
    	
    }
	
    @Test
    public void hw8(){
    	
    	Scanner sc = new Scanner(System.in);
		System.out.println("请输入1(爸爸)或2(妈妈)或3(爷爷)或4(奶奶)");
		int s = sc.nextInt();
		sc.close();
		
		switch(s){
		
		case 1: System.out.println("与爸爸通话中");break;
		case 2: System.out.println("与妈妈通话中");break;
		case 3: System.out.println("与爷爷通话中");break;
		case 4: System.out.println("与奶奶通话中");break;
		default: System.out.println("号码不对");break;
		}
    }
	//实心四边形
    @Test
    public void hw9(){
    	
    	for(int hang=1;hang<=4;hang++){
			for(int kg=1;kg<=4-hang;kg++){
				System.out.print(" ");
			}
			//System.out.print("*");
			for(int xx=1;xx<=2*hang-1;xx++)
				System.out.print("*");
				System.out.println();
		}
		for(int hang=5;hang<=7;hang++){
			
			for(int kg=1;kg<=hang-4;kg++)
				System.out.print(" ");
			for(int xx=1;xx<=15-2*hang;xx++){
				System.out.print("*");
				
			}
			System.out.println();
		}
    }
    //空心四边形
    @Test
	public void hw10(){
    	for(int hang=1;hang<=4;hang++){
			for(int kg=1;kg<=4-hang;kg++){
				System.out.print(" ");
			}
			//System.out.print("*");
			for(int xx=1;xx<=2*hang-1;xx++){
				if(xx==1 || xx==(2*hang-1)){
					System.out.print("*");
				}else{
					
					System.out.print(" ");
				}
			     
			}
				System.out.println();
		}
		for(int hang=5;hang<=7;hang++){
			
			for(int kg=1;kg<=hang-4;kg++)
				System.out.print(" ");
			for(int xx=1;xx<=15-2*hang;xx++){
				
				if(xx==1 || xx==(15-2*hang))
					System.out.print("*");
				else{
					System.out.print(" ");
				}
				
			}
			System.out.println();
		}
	}
    
    //乘法表重上到下
	@Test
	public void fj(){
	//while 打印	
	    int a=1;	
		while(a<=9){
			int b=a;
			while(b<=9){
				int sum =a*b;
			    System.out.print(a+"*"+b+"="+sum+"\t");	
			    b++;	
			}
		 System.out.println();		
		 a++;
		}
		
		 System.out.println("--------------");
		
		int b=1;
		do{
			int b1=b;
			do{
				int sum =b*b1;
			    System.out.print(b+"*"+b1+"="+sum+"\t");	
			    b1++;
			}while(b1<=9);
			 System.out.println();		
			 b++;
		}
		while(b<=9);
	 System.out.println("--------------");
	//for 打印	
		for(int i=1;i<=9;i++){
			for(int b1=i;b1<=9;b1++)
			{
				System.out.print(i+"*"+b1+"="+(i*b1)+"\t");
			}
			System.out.println();
		    
		}
	 System.out.println("--------------");	
	}
	//乘法表重下到上
	@Test
	public void fj01(){
		
	    //while循环打印
		int a=9;
		while(a>=1){
			int b=a;
			while(b<=9){
				
				System.out.print(a+"*"+b+"="+(a*b)+"\t");
				b++;
			}
		 a--;
		 System.out.println();
		}
		
		 System.out.println("--------------");	
	
        //dowhile	
		int a1=9;
		do{
			int b1=a1;
			do{
				int sum =a1*b1;
			    System.out.print(a1+"*"+b1+"="+sum+"\t");	
			    b1--;
			}while(b1>=1);
			 System.out.println();		
			 a1--;
		}
		while(a1>=1);
		
	    System.out.println("--------------");	

	    //for循环打印	
		for(int i=9;i>=1;i--){
			for(int b=i;b<=9;b++){
				
				System.out.print(i+"*"+b+"="+(i*b)+"\t");
			}
			
		    System.out.println();
		}	
	}
	
	
	
}
